package com.atguigu.yygh.hosp.controller.user;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.hosp.service.DepartmentService;
import com.atguigu.yygh.hosp.service.HosptialService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.DepartmentVo;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/*==========================================
      时 间:   2022-03-09
      讲 师:   刘  辉
      描 述:   尚硅谷教学团队
 ==========================================*/
@Api(tags = "医院显示接口")
@RestController
@RequestMapping("/user/hosp/hospital")
public class UserHospitalController {

    @Autowired
    private HosptialService hospitalService;
    @Autowired
    private DepartmentService departmentService;



    //根据医院编号hoscode查询医院详细信息
    @GetMapping("/getHospitalDetailByHoscode/{hoscode}")
    public R getHospitalDetailByHoscode(@PathVariable String hoscode){
        Hospital hospital = hospitalService.getHospitalDetailByHoscode(hoscode);
        return R.ok().data("hospital",hospital);
    }


    //根据医院编号hoscode查询医院科室信息
    @GetMapping("/getDeptListByHoscode/{hoscode}")
    public R getDeptListByHoscode(@PathVariable String hoscode){
        List<DepartmentVo> departmentList = departmentService.getDepartmentList(hoscode);
        return R.ok().data("list",departmentList);
    }

    @GetMapping("/{pageNum}/{pageSize}")
    public R getHospitalPage(@PathVariable Integer pageNum,
                             @PathVariable Integer pageSize,
                             HospitalQueryVo hospitalQueryVo){
        Page<Hospital> page= hospitalService.getHospitalPage(pageNum,pageSize,hospitalQueryVo);


        return R.ok().data("pages",page);
    }


    @GetMapping("/findByName/{name}")
    public R findByName(@PathVariable String name){
        List<Hospital> hospitalList=hospitalService.findByName(name);
        return R.ok().data("list",hospitalList);
    }
}
